package com.guashu.springbootasynchronous.async.springApplicationEvent;

import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Component
public class CustomEventListener implements ApplicationListener<CustomEvent> {

    @Async // 声明异步执行
    @Override
    public void onApplicationEvent(CustomEvent event) {
        System.out.println("接收客户端事件 - " + event.getMessage());
        // 模拟耗时操作
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("完成处理事件.");
    }
}
